package com.yellowpage.ndc.action;
  
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.ndc.data.ProdCustomerHis;
import com.yellowpage.ndc.service.ProdCustomerHisService;

public class ProdCustomerHisAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<ProdCustomerHis> prodCustomerHisList = new ArrayList<ProdCustomerHis>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private ProdCustomerHis prodCustomerHis;
	private ProdCustomerHisService prodCustomerHisService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_customerId;
		private String query_createUser;
		private String query_createTime;
		private String query_note;
		private String query_id;
		private String query_type;
		private String query_content;
		
		private String query_customerCode;
		private String query_customerName;
		private String query_userName;
		private String query_displayName;
		private String query_createTimeStart;
		private String query_createTimeEnd;
		
		
		
		private Map typeMap = new HashMap();
		
	public void prepare() {
		super.prepare();
		typeMap.put("0", "新增");
		typeMap.put("1", "修改");
		typeMap.put("2", "删除");
		typeMap.put("3", "360下线");
		typeMap.put("4", "删除还原");
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.prodCustomerHis = prodCustomerHisService.getProdCustomerHis(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
			    queryMap.put("customerCode", query_customerCode);
	    	    queryMap.put("customerName", query_customerName);
	    	    queryMap.put("userName", query_userName);
	    	    queryMap.put("displayName", query_displayName);
	    	    queryMap.put("timeStart", query_createTimeStart);
	    	    queryMap.put("timeEnd", query_createTimeEnd);
	    	    queryMap.put("type", query_type);
	    	    
	    	    	
		resultList = prodCustomerHisService.queryProdCustomerHisByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		prodCustomerHisService.saveProdCustomerHis(prodCustomerHis);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    	    	    	    	    	    	    if (prodCustomerHis.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    	    	    	    	    	    	    if (prodCustomerHis.getContent().length() == 0) {
			this.addActionError("** Content 不能为空 !");
		}
			    	    
		this.setValidatorResult("/ndc/ProdCustomerHisAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    prodCustomerHis = prodCustomerHisService.getProdCustomerHis(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    prodCustomerHisService.updateProdCustomerHis(prodCustomerHis);	

		message = "修改成功!";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    			    			    			    if (prodCustomerHis.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    			    			    			    if (prodCustomerHis.getContent().length() == 0) {
			this.addActionError("** Content 不能为空 !");
		}
			    		this.setValidatorResult("/ndc/ProdCustomerHisUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.prodCustomerHisService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲突删除失败 !");
		}
		
		
		return queryByPage();
	}	
	
	

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setProdCustomerHis(ProdCustomerHis prodCustomerHis) {
		this.prodCustomerHis = prodCustomerHis;
	}
	
	public ProdCustomerHis getProdCustomerHis() {
		return prodCustomerHis;
	}
	 
	 
	 public void setProdCustomerHisService(ProdCustomerHisService prodCustomerHisService) {
		this.prodCustomerHisService = prodCustomerHisService;
	}
	
	public List<ProdCustomerHis> getProdCustomerHisList() {
		return prodCustomerHisList;
	}

	public void setProdCustomerHisList(List<ProdCustomerHis> prodCustomerHisList) {
		this.prodCustomerHisList = prodCustomerHisList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_customerId() {
        return this.query_customerId;
    }
    
    public void setQuery_customerId(String customerId){
        this.query_customerId = customerId;
    }    

        public String getQuery_createUser() {
        return this.query_createUser;
    }
    
    public void setQuery_createUser(String createUser){
        this.query_createUser = createUser;
    }    

        public String getQuery_createTime() {
        return this.query_createTime;
    }
    
    public void setQuery_createTime(String createTime){
        this.query_createTime = createTime;
    }    

        public String getQuery_note() {
        return this.query_note;
    }
    
    public void setQuery_note(String note){
        this.query_note = note;
    }    

        public String getQuery_id() {
        return this.query_id;
    }
    
    public void setQuery_id(String id){
        this.query_id = id;
    }    

        public String getQuery_type() {
        return this.query_type;
    }
    
    public void setQuery_type(String type){
        this.query_type = type;
    }    

        public String getQuery_content() {
        return this.query_content;
    }
    
    public void setQuery_content(String content){
        this.query_content = content;
    }

	public String getQuery_customerCode() {
		return query_customerCode;
	}

	public void setQuery_customerCode(String query_customerCode) {
		this.query_customerCode = query_customerCode;
	}

	public String getQuery_customerName() {
		return query_customerName;
	}

	public void setQuery_customerName(String query_customerName) {
		this.query_customerName = query_customerName;
	}

	public String getQuery_userName() {
		return query_userName;
	}

	public void setQuery_userName(String query_userName) {
		this.query_userName = query_userName;
	}

	public String getQuery_displayName() {
		return query_displayName;
	}

	public void setQuery_displayName(String query_displayName) {
		this.query_displayName = query_displayName;
	}

	public String getQuery_createTimeStart() {
		return query_createTimeStart;
	}

	public void setQuery_createTimeStart(String query_createTimeStart) {
		this.query_createTimeStart = query_createTimeStart;
	}

	public String getQuery_createTimeEnd() {
		return query_createTimeEnd;
	}

	public void setQuery_createTimeEnd(String query_createTimeEnd) {
		this.query_createTimeEnd = query_createTimeEnd;
	}

	public Map getTypeMap() {
		return typeMap;
	}

	public void setTypeMap(Map typeMap) {
		this.typeMap = typeMap;
	}    

    
	
}
